﻿@model Sealight.UI.WebUI.Models.ProductSpecificationAttributeViewModel
           @{
               
               string id = string.Empty, specificationAttribute = string.Empty, attributeOption = string.Empty, displayOrder = "1";
               bool allowFilter = false, showProductPage = true;
               
               if(Model!=null)
               {
                   id = Model.ID.ToString();
                   specificationAttribute = Model.SpecificationAttributeID.ToString();
                   attributeOption = Model.SpecificationAttributeOptionID.ToString();
                   displayOrder = Model.DisplayOrder.ToString();
                   allowFilter = Model.AllowFiltering;
                   showProductPage = Model.ShowOnProductPage;                   
               }
               var listSpecificationAttribute = Sealight.UI.WebUI.Services.ProductService.GetAllSpecificationProductAttribute();
               IList<Sealight.UI.WebUI.Models.SpecificationAttributeOptionViewModel> options = null;
               if(!string.IsNullOrEmpty(specificationAttribute))
               {
                   options = Sealight.UI.WebUI.Services.ProductService.GetAllOptionBySpecificationId(Model.SpecificationAttributeID);
               }           
               
           }

           <script language="javascript" type="text/javascript">
               $(function () {

                   $('#specificationAttribute').change(function () {
                       var specid = $('#specificationAttribute').val();

                       if (specid == '') return;
                       $.ajax({
                           type: "POST",
                           url: "/admin/product/GetListOptionForSpecificationAttr",
                           data: ({ id: specid }),
                           dataType: "json",
                           error: function (xhr, status, error) { },
                           success: function (d) {
                               if (d != null) {
                                   if (d.OperationComplete != null && d.OperationComplete == false && d.ErrorCode != null) {
                                       if (d.ErrorFriendlyMessage != null) {
                                           ShowErrorMessage(d.ErrorFriendlyMessage);
                                       }
                                       return;
                                   }
                                   $('#attributeOption').children().remove();
                                   if (d.length > 0) {
                                       for (var i = 0; i < d.length; i++) {                                          
                                           $('#attributeOption').append($("<option></option>").val(d[i].ID).text(d[i].Name));

                                       }
                                   }
                               }
                           },
                           complete: function (d) {
                           },
                           cache: false
                       }); //end .ajax call

                   });


               });
           </script>
<div>
    @using (Ajax.BeginForm("SaveUpdateProductSpecificationAttributeOption", new AjaxOptions { OnComplete = "resetAddUpdateProductSpecificationOption" }))
    {       
        <p>           
            <table class="adminContent">
                <tbody>
                    <tr>
                        <td class="adminTitle">                           
                               Chọn thuộc tính đặc biệt:
                        </td>
                        <td class="adminData">
                      
                            <select     name="specificationAttribute" id="specificationAttribute" class="adminInput">
                            <option value="">--Chọn thuộc tính--</option>
                           @if (listSpecificationAttribute != null)
                           {
                            foreach (var a in listSpecificationAttribute)
                            {
                                if (a.IDString == specificationAttribute)
                                {
                                <option selected="selected" value="@a.IDString">@a.Name</option>
                                }
                                else
                                {
                                <option value="@a.IDString">@a.Name</option>
                                }

                            }
                           }
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td class="adminTitle">
                           Thuộc tính tùy chọn:
                        </td>
                        <td class="adminData">
                            <select name="attributeOption" id="attributeOption">
                            <option value="">--Chọn--</option>
                                @if (options != null)
                                {
                                    foreach (var a in options)
                                    {
                                        if (a.ID.ToString() == attributeOption)
                                        {
                                    <option selected="selected" value="@a.ID.ToString()">@a.Name</option>
                                }
                                else
                                {
                                    <option value="@a.ID.ToString()">@a.Name</option>
                                }
                            }
                           }
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td class="adminTitle">
                           Cho phép lọc:
                        </td>
                        <td class="adminData">
                            <input type="checkbox" name="allowFilter" id="allowFilter" checked="@allowFilter.ToString().ToLower()"/>
                        </td>
                    </tr>
                    <tr>
                        <td class="adminTitle">                          
                          Hiển thị ở trang sản phẩm:
                        </td>
                        <td class="adminData">
                            <input  type="checkbox" checked="@showProductPage.ToString().ToLower()" name="showProductPage" id="showProductPage"/>
                        </td>
                    </tr>
                    <tr>
                        <td class="adminTitle">                          
                            <span title="Display order of the specification attribute. 1 represents the top of the list.">
                                Thứ tự hiển thị</span>
                        </td>
                        <td class="adminData">
                            <input type="text" value="@displayOrder" class="adminInput" name="displayOrder" id="displayOrder"/>                           
                        </td>
                    </tr>                
                </tbody>
            </table>
        </p>            
        <div class="form-actions">
         @Html.Hidden("productId", ViewData["productId"])
         @Html.Hidden("psId", id)
            <button type="submit" class="t-button t-state-default">
                Lưu</button>
        </div>
    }
</div>